package com.tspark.tspark1.zoo.util;

/**
 * 用户的每次访问都是一个独立的线程
 * 此工具类用于在当前线程保存用户的id
 */
public class ThreadLocalUtil {
    //存储uid
    public static ThreadLocal<Integer> uidLocal = new ThreadLocal<>();
    //存储是否为管理员
    public static ThreadLocal<Integer> isAdminLocal = new ThreadLocal<>();

    public static void setCurrentId(Integer id) {
        uidLocal.set(id);
    }

    public static Integer getCurrentId() {
        return uidLocal.get();
    }

    public static void removeCurrentId() {
        uidLocal.remove();
    }

    public static void setIsAdmin(Integer isAdmin){
        isAdminLocal.set(isAdmin);
    }

    public static void getIsAdmin(Integer isAdmin) {
        isAdminLocal.get();
    }

    public static void removeIsAdmin(){
        isAdminLocal.remove();
    }
}
